package com.kede.typehanlder.zhi;

import com.kede.ienum.zhi.ZhiOrderStatusEnum;
import com.kede.ienum.zhi.ZhiOrderTypeEnum;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/***
 ** @Author:Pr.li
 ** @Description:
 ** @Date: create in 2023/6/1 17:37
 ***/
public class ZhiOrderStatusEnumTypeHanlder extends BaseTypeHandler<ZhiOrderStatusEnum> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, ZhiOrderStatusEnum parameter, JdbcType jdbcType) throws SQLException {
        ps.setInt(i,parameter.getEnumIndex());
    }

    @Override
    public ZhiOrderStatusEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
        int code = rs.getInt(columnName);
        ZhiOrderStatusEnum instance = ZhiOrderStatusEnum.parse(code);
        return instance;
    }

    @Override
    public ZhiOrderStatusEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        int code = rs.getInt(columnIndex);
        ZhiOrderStatusEnum instance = ZhiOrderStatusEnum.parse(code);
        return instance;
    }

    @Override
    public ZhiOrderStatusEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return null;
    }
}
